from datetime import datetime, timezone
from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from typing import TYPE_CHECKING

from .base import Base


if TYPE_CHECKING:
    from .search_order import SearchOrder


class ADS(Base):
    __tablename__ = "ads"

    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[str] = mapped_column(String(50), nullable=False)
    price: Mapped[int] = mapped_column(default=0, nullable=True)
    currency: Mapped[str] = mapped_column(String(8), nullable=True)
    descriptions: Mapped[str] = mapped_column(String(256), nullable=False)
    url: Mapped[str] = mapped_column(String(256), nullable=False)
    data_marker: Mapped[str] = mapped_column(String(32), nullable=False)
    created_at: Mapped[datetime] = mapped_column(default=datetime.now(timezone.utc))
    order_id: Mapped[int] = mapped_column(ForeignKey("search_order.id"))

    order: Mapped["SearchOrder"] = relationship(back_populates="ads")
